/*
 * findPCB.c
 *
 *  Created on: Oct 2, 2013
 *      Author: Joseph DeLong
 */

#include <stdlib.h>
#include "mpx_pcb.h"
/*
 * FIND PCB
 * Written by Joseph DeLong
 * Debugged by Alex Newcomer
 * Searches all queues for a process with the given name.
 * Parameters: Process Name
 * Returns:
 * 	Pointer to the PCB if found
 * 	NULL if error
 */
struct MPX_PCB* findPCB(char processName[9], struct MPX_Q *r, struct MPX_Q *b) {
	struct MPX_PCB *temp;
	int found = 0, count = 0, count1 = 0;
	(temp) = (*r).head;
	do	{
	if(count){
	(temp) = (*temp).next;
	}
	count = 1;
		if(!strcmp((*temp).processName,processName)) { //if names match
			found = 1;
			break;
		}
	} while ((*temp).next != NULL);
	if(found != 0) {
	
		(temp) = (*b).head;
	do	{
	if(count1){
	(temp) = (*temp).next;
	}
	count1 = 1;
		if(!strcmp((*temp).processName,processName)) { //if names match
			found = 1;
			break;
		}
	} while ((*temp).next != NULL);

	
	/*
		for(temp = (*b).head; *temp; temp = (*temp).next) {
			if(!strcmp((*temp).processName,processName)) { //if names match
				found = 1;
				break;
			}
		}
		*/
	}
	return (*(*temp).prev).next;
}
